package com.example.yuejianapp14.Activity.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.yuejianapp14.Activity.Activity.ActActivity;
import com.example.yuejianapp14.Activity.JavaBean.Act;
import com.example.yuejianapp14.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 张森 on 2017/9/29.
 */

public class ActAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;
    private List<Act> mDataList;
    private LayoutInflater mLayoutInflater;

    public ActAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v =mLayoutInflater.from(parent.getContext()).inflate(R.layout.actcard,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Act entity = (Act) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.Act_name.setText(entity.getActivity());



        Picasso.with(mContext).load("http://10.0.2.2/YueJian/Public/photo/activity/"+entity.getActivitypic()).into(viewHolder.Act_pic);
        // viewHolder.news_stars.setRating(Float.parseFloat(entity.get("news_stars").toString()));
        // viewHolder.news_thumb.setIIntegemageResource(r.parseInt(entity.get("news_thumb").toString()));
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,ActActivity.class);
                intent.putExtra("actid",entity.getActivityid());
                intent.putExtra("actinfo",entity.getInstruction());
                intent.putExtra("actcost",entity.getCost());
                intent.putExtra("actaddress",entity.getAddress());
                intent.putExtra("acttime",entity.getTime());
                intent.putExtra("actpic",entity.getActivitypic());
                intent.putExtra("actphone",entity.getContact());



                mContext.startActivity(intent);
            }
        });





    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView Act_pic;
        TextView Act_name;
        LinearLayout Act_container;

        public ViewHolder(View itemView) {
            super(itemView);
            Act_name = (TextView) itemView.findViewById(R.id.act_name);
            Act_pic = (ImageView) itemView.findViewById(R.id.act_pic);
            Act_container = (LinearLayout) itemView.findViewById(R.id.act_container);
        }
    }
}
